home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 9 / 009.d81 / dos #20 < prev    next >
Text File  |  2022-08-26  |  2KB  |  149 lines

  1.  
  2.       DOS & DON'TS -- Part 20
  3.       === = ======    ==== ==
  4.  
  5.           By Jimmy Weiler
  6.  
  7.  
  8.  
  9.  
  10.   You should be tired of ordinary
  11.  
  12. SEQ files by now -- we've covered how
  13.  
  14. to open, write, read, and append them.
  15.  
  16. There's not a lot left you can do with
  17.  
  18. them unless you're a lot more
  19.  
  20. sophisticated than we are.
  21.  
  22.   This time let's dig into RELative
  23.  
  24. files.  (On most OTHER computers
  25.  
  26. they're called random access... but
  27.  
  28. Commodore uses 'random access' to
  29.  
  30. describe user-controlled sector-by-
  31.  
  32. sector disk i/o's so they had to
  33.  
  34. call this type of file something
  35.  
  36. else.)
  37.  
  38.   SEQuential files can be thought of
  39.  
  40. as one big chunk of data, like a
  41.  
  42. scroll.  Relative files are more like
  43.  
  44. a bunch of little chunks, all the
  45.  
  46. same size, like the index cards in
  47.  
  48. your recipe file, or the pages in a
  49.  
  50. book.  The disadvantage of SEQ files
  51.  
  52. is that, just like a scroll, you have
  53.  
  54. to start at the beginning and 'unroll'
  55.  
  56. the contents in the order they were
  57.  
  58. written.  Relative files overcome
  59.  
  60. this disadvantage by allowing you to
  61.  
  62. access any individual piece of the
  63.  
  64. file directly, without scanning over
  65.  
  66. the rest of the file.
  67.  
  68.   Graphically the data in a sequential
  69.  
  70. and a random file might be represented
  71.  
  72. like this:
  73.  
  74.  
  75. Sequential file:
  76.  
  77.  
  78. data/more data/even more data/& some m
  79. ore data/and the end
  80.  
  81.  
  82.  
  83. Relative file:
  84.  
  85.  
  86. /data             //more data        /
  87. /even more data   //& some more data /
  88. /and the end      /
  89.  
  90.  
  91.   As you can see, the data is packed
  92.  
  93. into the SEQ file one bit after
  94.  
  95. another, in five records of unequal
  96.  
  97. sizes.  In the REL file, there are
  98.  
  99. still five records, but they are all
  100.  
  101. the same size.  Because all the
  102.  
  103. records are equally large, DOS is able
  104.  
  105. calculate the location on the disk of
  106.  
  107. any piece of data relative to the
  108.  
  109. start of the file and access it
  110.  
  111. directly.
  112.  
  113.   SEQ files are useful when you are
  114.  
  115. dealing with information that will all
  116.  
  117. be read into the computer's memory at
  118.  
  119. one time -- letters, small data files,
  120.  
  121. etc.
  122.  
  123.   REL files are useful when you have
  124.  
  125. too much information to read into
  126.  
  127. memory at once, or when you only want
  128.  
  129. to access a little of it at a time.
  130.  
  131. This makes them useful for business
  132.  
  133. and record keeping applications where
  134.  
  135. small amounts of data are to be kept
  136.  
  137. 'on file' for lots of people.
  138.  
  139.   Enough generalities -- let's get
  140.  
  141. right into using RELative files.
  142.  
  143. We'll cover opening, closing, writing,
  144.  
  145. and reading them.
  146.  
  147.  
  148. -------- Continued in Part 21 --------
  149.